﻿using FlexFlow.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlexFlow.Runtime
{
    /// <summary>
    /// 表示流程实例管理器
    /// </summary>
    public class ProcessInstanceManager : ManagerBase
    {
        /// <summary>
        /// 获取或设置默认的流程实例管理器
        /// </summary>
        public static ProcessInstanceManager Default { get; set; }
        /// <summary>
        /// 创建流程实例
        /// </summary>
        /// <param name="processId">
        /// 要创建的流程实例对应的流程Id
        /// </param>
        /// <param name="userId">
        /// 执行创建请求的用户Id
        /// </param>
        /// <returns>
        /// 操作结果
        /// </returns>
        public OperateResult CreateInstance(Guid processId,Guid userId)
        {
            ProcessInstance procIns = this.Components.ProcessInstanceProvider.Create();
            procIns.State = ProcessInstanceState.Initiated;
            procIns.ProcessId = processId;
            procIns.Creator = userId;
            if (!this.Components.ProcessInstanceProvider.Add(procIns))
            {
                return new OperateResult()
                {
                    ResultCode = 0x090101,
                    Message = "数据操作失败！"
                };
            }

            return OperateResult.SuccessResult(procIns);
        }

        static ProcessInstanceManager()
        {
            Default = new ProcessInstanceManager();
        }
    }
}
